const total = 20
const pageSize = 100

export default function () {

    const list = []
    for (let i = 0; i < pageSize; i++) {
        // 为不同教练生成不同的时间段组合
        let timeSlots = [];

        // 随机1-4
        const random = Math.floor(Math.random() * 4) + 1;

        if (random === 1) {
            // 全天可约
            timeSlots = [
                { id: i * 10 + 1, startTime: '08:00', endTime: '12:00', type: 1 },
                { id: i * 10 + 2, startTime: '13:00', endTime: '14:00', type: 2 },
                { id: i * 10 + 3, startTime: '14:00', endTime: '15:00', type: 2 },
                { id: i * 10 + 4, startTime: '15:00', endTime: '17:00', type: 1 },
                { id: i * 10 + 5, startTime: '18:00', endTime: '22:00', type: 1 },
            ];
        } else if (random === 2) {
            // 部分时段可约
            timeSlots = [
                { id: i * 10 + 1, startTime: '09:00', endTime: '10:00', type: 1 },
                { id: i * 10 + 2, startTime: '10:00', endTime: '11:00', type: 2 },
                { id: i * 10 + 3, startTime: '11:00', endTime: '12:00', type: 2 },
                { id: i * 10 + 4, startTime: '14:00', endTime: '16:00', type: 1 },
                { id: i * 10 + 5, startTime: '16:00', endTime: '18:00', type: 2 },
            ];
        } else if (random === 3) {
            timeSlots = [];
            // 无可约时段或休息
            // timeSlots = [
            //     { id: i * 10 + 1, startTime: '09:00', endTime: '12:00', type: 2 },
            //     { id: i * 10 + 2, startTime: '14:00', endTime: '16:00', type: 3 },
            //     { id: i * 10 + 3, startTime: '16:00', endTime: '18:00', type: 2 },
            // ];
        } else if (random === 4) {
            timeSlots = [];
        } else {
            timeSlots = null
        }

        // 计算可排时长
        let availableHours = timeSlots
            .filter(slot => slot.type === 1)
            .reduce((total, slot) => {
                const start = new Date(`2024-01-01 ${slot.startTime}`);
                const end = new Date(`2024-01-01 ${slot.endTime}`);
                return total + (end - start) / (1000 * 60 * 60);
            }, 0);

        // 如果 availableHours ===0 ， 百分之50概率设置为null
        if (availableHours === 0) {
            if (Math.random() < 0.5) {
                availableHours = null;
            }
        }

        if (!availableHours) {
            timeSlots = null
        }

        list.push({
            id: i + 1,
            name: `教练${i + 1}`,
            account: `trainer${i + 1}`,
            jobNature: i % 2 === 0 ? '全职' : '兼职',
            availableHours: availableHours,
            timeSlots: timeSlots,
        })
    }
    return new Promise((resolve) => {
        setTimeout(() => {
            resolve({
                "code": 0,
                "message": "请求成功",
                "data": {
                    "current": 1,
                    "size": pageSize,
                    "total": total,
                    "list": list
                },
                "timestamp": 1743156247859,
                "requestId": "517C8733-908A-4A13-9F67-4BB37914CB7C"
            });
        }, 100);
    });
}